﻿<!DOCTYPE html>
<html manifest="./mapcache.manifest">
<head>
<meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
<meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
<title>Sogou Maps </title>
<style type="text/css">
html{height:100%}
body{height:100%;margin:0px;padding:0px}
#map{height:100%}
</style>
<script type="text/javascript" src="http://api.go2map.com/maps/js/api_v2.5.1.js"></script>
</head>

<body>
    <div id="map"></div>
        <div id="result" style="width:0px;height:0px;display:none;margin:0px;padding:0px;">
        </div>
</body>
<script>
//var myLatLng = new sogou.maps.Point(window.qml.ini_center);
var myLatLng = new sogou.maps.Point(12957062,4827187);
//var myLatLng = window.qml.ini_center;
var myOptions = {
  zoom: 10,
  center: myLatLng,
  mapControl: false
};
var map = new sogou.maps.Map(document.getElementById("map"), myOptions);
//map.setCenter(window.qml.ini_center, window.qml.ini_level);

var marker = "";


//new sogou.maps.Marker({
//        map: map
//    });

var scheme_detail = "";

sogou.maps.event.addListener(map, 'idle', function() {
        window.qml.mapbounds = map.getBounds().toString();
        window.qml.mapcenter = map.getCenter().toString();
        window.qml.zoom_level = map.getZoom();
        window.qml.qmlCall();
    });

//onIdle:
//{
    //alert("idle changed !!!! ");
    //window.qml.poi0 = map.getBounds().toString();
    //window.qml.qmlCall();
//}

function getboundforqml()
{
    window.qml.mapbounds = map.getBounds().toString();
    window.qml.qmlCall();
}

function positionCallback(poi)
{
    alert("position callback ...................... ");
    if(poi&&poi.length>0)
    {
        map.panTo(poi[0]);
    }
}

function getSchemeDetail(s_index)
{
    alert("getSchemeDetail" + scheme_detail);
    if(scheme_detail.getSchemeNum()>0)
    {
        alert("not null" + s_index);
        var scheme = scheme_detail.getScheme(s_index);
        //alert("1");
        var new_detail = new sogou.maps.BusDetail(scheme,busdetailcallback);
        //alert("2");
        new_detail.setRenderer(bus_renderer);
        alert("after render");
    }
}

function busdetailcallback(a)
{
    //window.qml.notify(3000, "等待服务器响应中，响应时间取决于当前网络状况");
    alert("in detail");
    alert(a);
    alert(a.status);
    if (a.status == "error")
    {
        //window.qml.notify(1500, "搜索成功！");
        window.qml.notify(4500, a.error);
    }
    else
    {
        window.qml.notify(1500, "详细路线搜索成功！");
    }
    alert(a.error);
    var bdr_data = a.data;
    alert(bdr_data.start.walkdist);
    alert(bdr_data.end.walkdist);
    alert(bdr_data.fare);
    alert(bdr_data.transferinfo.length);
    var tfinfo = bdr_data.transferinfo;
    window.qml.clear_bus_route();
    for (var i=0; i < tfinfo.length; i++)
    {
        alert("tfinfo : " + i + " , " + tfinfo[i].upname + " , " + tfinfo[i].downname);
        //window.qml.route_input(tfinfo[i].upname, tfinfo[i].downname);
        //alert(tfinfo[i].subwayinxy + " , " + tfinfo[i].subwayoutxy);
        alert("up xy : " + tfinfo[i].upx + " , " + tfinfo[i].upy);
        alert(tfinfo[i].linename);
        alert("down xy : " + tfinfo[i].downx + " , " + tfinfo[i].downy);
        //alert(tfinfo[i].points.txt);
        window.qml.route_input(tfinfo[i].upname, tfinfo[i].upx + "," + tfinfo[i].upy, tfinfo[i].linename, tfinfo[i].downname, tfinfo[i].downx + "," + tfinfo[i].downy);
    }
    window.qml.route_to_navi();
}

function buscallback(a){
        alert(a.status);
        if (a.status == "error")
        {
            //window.qml.notify(1500, "搜索成功！");
            window.qml.notify(4500, a.error);
        }
        else
        {
            window.qml.notify(1500, "路线搜索成功！");
        }
        //alert(a.error);
        //alert("in callback");
        //alert(a);
        var b=a.data;

        //alert(b);
        if(a&&b){
                if(b.getSchemeNum()>0){
                        scheme_detail = b;
                        alert("scheme number :" + b.getSchemeNum());
                        //var scheme0 = b.getScheme(0);
                        var linegroup = b.group;
                        alert("line count: " + linegroup.length);
                        window.qml.bus_model_clear();
                        for (var i = 0; i < linegroup.length; i++)
                        {
                            //alert(i);
                            var linenames_s = "";
                            alert(linegroup[i].time + " , " + linegroup[i].walkdist + " , " + linegroup[i].line.length);
                            for (var j = 0; j < linegroup[i].line.length; j++)
                            {
                            //    alert(linegroup[i].line[j].dets);
                                alert(linegroup[i].line[j].linenames);
                                linenames_s = linenames_s + "," + linegroup[i].line[j].linenames;
                                alert(linenames_s);
                            }
                            window.qml.bus_model_append(linegroup[i].time, linegroup[i].walkdist, linegroup[i].line.length, linenames_s);
                        }
                        //alert(scheme0.toString());
                        //var detail=new sogou.maps.BusDetail(scheme0,busdetailcallback);
                        //alert(detail.toString());
                        //detail.setRenderer(bus_renderer);
                        //alert("after setRenderer");
                }
        }
};

//var des = window.qml.bus_end;
//var ori = window.qml.bus_start;

//var request={
// 'map':map,        //Map
// 'destination':des,
// 'origin':ori
//}
var bus=new sogou.maps.Bus();
var bus_renderer = new sogou.maps.BusDetailRenderer({'map':document.getElementById('map')});

function getInstance(a)
{
  a.hasOwnProperty("_instance")||(a._instance = new a);
  return a._instance
}
var convertor = getInstance(sogou.maps.Convertor);

//alert("what the fxxk ??? ");
//bus.route(request,callback);
</script>
</html>
